package com.freeng.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.freeng.common.annotation.Log;
import com.freeng.common.core.controller.BaseController;
import com.freeng.common.core.domain.AjaxResult;
import com.freeng.common.enums.BusinessType;
import com.freeng.business.domain.SystemNotification;
import com.freeng.business.service.ISystemNotificationService;
import com.freeng.common.utils.poi.ExcelUtil;
import com.freeng.common.core.page.TableDataInfo;

/**
 * 预警提示Controller
 * 
 * @author freeng
 * @date 2024-09-10
 */
@RestController
@RequestMapping("/system/notification")
public class SystemNotificationController extends BaseController
{
    @Autowired
    private ISystemNotificationService systemNotificationService;

    /**
     * 查询预警提示列表
     */
    @PreAuthorize("@ss.hasPermi('system:notification:list')")
    @GetMapping("/list")
    public TableDataInfo list(SystemNotification systemNotification)
    {
        startPage();
        List<SystemNotification> list = systemNotificationService.selectSystemNotificationList(systemNotification);
        return getDataTable(list);
    }

    /**
     * 导出预警提示列表
     */
    @PreAuthorize("@ss.hasPermi('system:notification:export')")
    @Log(title = "预警提示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SystemNotification systemNotification)
    {
        List<SystemNotification> list = systemNotificationService.selectSystemNotificationList(systemNotification);
        ExcelUtil<SystemNotification> util = new ExcelUtil<SystemNotification>(SystemNotification.class);
        util.exportExcel(response, list, "预警提示数据");
    }

    /**
     * 获取预警提示详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:notification:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(systemNotificationService.selectSystemNotificationById(id));
    }

    /**
     * 新增预警提示
     */
    @PreAuthorize("@ss.hasPermi('system:notification:add')")
    @Log(title = "预警提示", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SystemNotification systemNotification)
    {
        return toAjax(systemNotificationService.insertSystemNotification(systemNotification));
    }

    /**
     * 修改预警提示
     */
    @PreAuthorize("@ss.hasPermi('system:notification:edit')")
    @Log(title = "预警提示", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SystemNotification systemNotification)
    {
        return toAjax(systemNotificationService.updateSystemNotification(systemNotification));
    }

    /**
     * 删除预警提示
     */
    @PreAuthorize("@ss.hasPermi('system:notification:remove')")
    @Log(title = "预警提示", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(systemNotificationService.deleteSystemNotificationByIds(ids));
    }
}
